package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.AwardInfoAndApplicantDto;
import com.zhangtai.modules.entity.salary.AwardInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-21 10:48:29
 */
@Mapper
public interface AwardInfoDao extends BaseMapper<AwardInfoEntity> {

    @Select("SELECT * FROM tb_award_info WHERE serial_num = #{serialNum}  ORDER BY create_time DESC")
    List<AwardInfoEntity> getAwardInfoBySerialNum(@Param("serialNum")String serialNum);


    @Select(
            "<script> SELECT\n" +
                    "\t* \n" +
                    "FROM\n" +
                    "\ttb_award_info tai\n" +
                    "\tLEFT JOIN tb_award_applicant taa ON tai.serial_num = taa.serial_num " +
                    " <where> tai.is_delete = 0 " +
                    "<if test='oid!=null'> and tai.oid = #{oid} </if>" +
                    "<if test='dateStart!=null and dateStart!=&apos;&apos;'>and tai.create_time &gt;= #{dateStart} and tai.create_time &lt;=#{dateEnd} </if>" +
                    "</where>  order by tai.create_time desc" +
                    "</script>"
    )
    List<AwardInfoAndApplicantDto> getAwardInfoPage(@Param(value = "oid") String oid,
                                                    @Param(value = "dateStart") String dateStart,
                                                    @Param(value = "dateEnd") String dateEnd,
                                                         Page<AwardInfoAndApplicantDto> page
    );


}
